const Redis = require("ioredis");
// const redis = new Redis({
//   host: "127.0.0.1",
//   port: 6379,
//   possword: "root",
//   db: 0,
// });

function connectRedis() {
  const client = new Redis({
    host: "47.94.17.177", // redis地址
    port: 6379, //端口
    password: "Root@1234", //密码
    db: 1,
  });

  return new Promise((resolve, reject) => {
    client.on("connect", () => {
      console.log("Redis连接成功");
      resolve(client);
    });

    client.on("error", (err) => {
      console.error("Redis连接失败:", err);
      reject(err);
    });
  });
}

// Create a shared Redis instance for the entire application.
// Redis is single-thread so you don't need to create multiple instances
// or use a connection pool.
// module.exports = redis;
module.exports = { connectRedis };
